<?php
namespace app\admin\controller;

use app\BaseController;
use app\common\facade\admin\EditroomAdmin;
use think\exception\ValidateException;

class Editroom extends BaseController
{
    public function pgmchannellist()
    {
        $param = $this->request->get([
            'day'
        ]);

        try {
            $data = EditroomAdmin::pgmchannellist($param);
        } catch (\Exception $e)
        {
            return exceptionJson($e->getMessage(), $e->getCode());
        }
            
        return successJson($data);
    }

    public function pgmchanneldel()
    {
        $ids = $this->request->delete();

        try {
            $data = EditroomAdmin::pgmchanneldel($ids);
        } catch (\Exception $e)
        {
            return exceptionJson($e->getMessage(), $e->getCode());
        }

        return successJson($data);
    }

    public function pgmtemplDel()
    {
        $ids = $this->request->delete();

        try {
            $data = EditroomAdmin::pgmtemplDel($ids);
        } catch(\Exception $e) {
            return exceptionJson($e->getMessage(), $e->getCode());
        }
        
        return successJson($data);
    }

    public function pgmchannelCheck() 
    {
        $param = $this->request->post([
            'pl_id' => $this->request->post('pl_id'),
            'word' => $this->request->post('review_word'),
            'status' => $this->request->post('review_status')
        ]);

        try {
            $data = EditroomAdmin::pgmchannelCheck($param);
        } catch (\Exception $e)
        {
            return exceptionJson($e->getMessage(), $e->getCode());
        }
            
        return successJson($data);
    }

    public function pgmchannelCreate()
    {
        $params = $this->request->post([
            'channel_id',
            'start_date',
            'fromdate',
            'fromtempl',
            'importType' 
        ]);

        try {
            $data = EditroomAdmin::pgmchannelCreate($params);
        } catch (\Exception $e)
        {
            return exceptionJson($e->getMessage(), $e->getCode());
        }
            
        return successJson($data);
    }

    // 总编室编单详情列表
    public function pgmdetaillist()
    {
        $params = $this->request->get([
            'type'
        ]);

        try{
            $data = EditroomAdmin::pgmdetaillist($params);
        }catch(\Exception $e) {
            return exceptionJson($e->getMessage(), $e->getCode());
        }

        return successJson($data);
    }

    // 总编室编单添加更新
    public function pgmdetailAddEdit()
    {
        $params = $this->request->post();
        try {
            $data = EditroomAdmin::pgmdetailAddEdit($params);
        } catch (\Exception $e)
        {
            return exceptionJson($e->getMessage(), $e->getCode());
        }
            
        return successJson($data);
    }

    public function pgmdetailDel()
    {
        $ids = $this->request->delete();

        try {
            $data = EditroomAdmin::pgmdetailDel($ids);
        } catch (\Exception $e)
        {
            return exceptionJson($e->getMessage(), $e->getCode());
        }

        return successJson($data);
    }

    // 节目模板列表
    public function pgmtemplList()
    {
        $channel_id = $this->request->get([
            'channel_id'
        ]);

        try{
            $data = EditroomAdmin::pgmtemplList($channel_id);
        } catch(\Exception $e) {
            return exceptionJson($e->getMessage(), $e->getCode());
        }

        return successJson($data);
    }

    // 节目模板写入
    public function pgmtemplAddEdit()
    {
        $param = $this->request->post([
            'channel_id',
            'pgmlist_id',
            'templ_id',
            'templ_name'
        ]);

        try {
            $data = EditroomAdmin::pgmtemplAddEdit($param);
        } catch(\Exception $e) {
            return exceptionJson($e->getMessage(), $e->getCode());
        }

        return successJson($data);
    }
}